package us.icitap.cm.business.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;
import us.icitap.utils.FormatingUtils;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="EXPERIMENT",schema="MPC")
public class Experiment implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 254016536035270236L;

	public enum ExperimentActionEnum {
		PHOTO("U fotografuan"),
		VIDEO("U filmuan");
		
		private String caption;
		private ExperimentActionEnum(String caption){
			this.caption = caption;
		}
		
		public String getCaption(){
			return this.caption;
		}
		
		public String toString(){
			return this.caption;
		}
	}
	
	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	
	
	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@Temporal(TemporalType.DATE)
	@Column(name="EXPERIMENT_DATE")
	private Date experimentDate;
	
	@ManyToOne
	@JoinColumn(name="EXPERIMENT_REASON_ID")
	private AppList experimentReason;
	
	@Column(name="PLACE_DONE", length=300)
	private String placeDone;
	
	@Enumerated(EnumType.STRING)
	@Column(name="EXP_ACTION")
	private ExperimentActionEnum experimentAction;
	
	@Column(length=500)
	private String result;
	
	
	
	public Experiment(){
		
	
	}
	
	public Experiment(Experiment experiment){
		this.experimentReason = experiment.getExperimentReason();
		this.experimentAction = experiment.getExperimentAction();
		this.placeDone = experiment.getPlaceDone();
		this.result = experiment.getResult();
	}

	
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}

	public AppList getExperimentReason() {
		return experimentReason;
	}

	public void setExperimentReason(AppList experimentReason) {
		this.experimentReason = experimentReason;
	}

	public String getPlaceDone() {
		return placeDone;
	}

	public void setPlaceDone(String placeDone) {
		this.placeDone = placeDone;
	}

	public ExperimentActionEnum getExperimentAction() {
		return experimentAction;
	}

	public void setExperimentAction(ExperimentActionEnum experimentAction) {
		this.experimentAction = experimentAction;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		
		result = prime
				* result
				+ ((experimentAction == null) ? 0 : experimentAction.hashCode());
		result = prime * result
				+ ((experimentDate == null) ? 0 : experimentDate.hashCode());
		result = prime
				* result
				+ ((experimentReason == null) ? 0 : experimentReason.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((placeDone == null) ? 0 : placeDone.hashCode());
		result = prime * result
				+ ((this.result == null) ? 0 : this.result.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Experiment other = (Experiment) obj;
		
		if (experimentAction != other.experimentAction)
			return false;
		if (experimentDate == null) {
			if (other.experimentDate != null)
				return false;
		} else if (!experimentDate.equals(other.experimentDate))
			return false;
		if (experimentReason == null) {
			if (other.experimentReason != null)
				return false;
		} else if (!experimentReason.equals(other.experimentReason))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (placeDone == null) {
			if (other.placeDone != null)
				return false;
		} else if (!placeDone.equals(other.placeDone))
			return false;
		if (result == null) {
			if (other.result != null)
				return false;
		} else if (!result.equals(other.result))
			return false;
		return true;
	}


	public boolean myEquals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Experiment other = (Experiment) obj;

		if (experimentAction != other.experimentAction)
			return false;
		if (experimentDate == null) {
			if (other.experimentDate != null)
				return false;
		} else if (!experimentDate.equals(other.experimentDate))
			return false;
		if (experimentReason == null) {
			if (other.experimentReason != null)
				return false;
		} else if (!experimentReason.equals(other.experimentReason))
			return false;
		
		if (placeDone == null) {
			if (other.placeDone != null)
				return false;
		} else if (!placeDone.equals(other.placeDone))
			return false;
		if (result == null) {
			if (other.result != null)
				return false;
		} else if (!result.equals(other.result))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "Eksperiment dt:" + FormatingUtils.formatedDate(this.experimentDate);
	}

	public Date getExperimentDate() {
		return experimentDate;
	}

	public void setExperimentDate(Date experimentDate) {
		this.experimentDate = experimentDate;
	}
	
}
